﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HCFramework.API.LINQ;

namespace C
{
    public class NewsController
    {
        public static void Insert(New a)
        {
            HCDataContext db = new HCDataContext();
            a.DateCreated = DateTime.Now;
            db.News.InsertOnSubmit(a);
            db.SubmitChanges();
        }

        public static void Update(New a, HCDataContext db)
        {
            db.SubmitChanges();
        }

        public static void Delete(int id)
        {
            HCDataContext db = new HCDataContext();
            New a = db.News.Where(
                ik => ik.NewsID == id).First();
            db.News.DeleteOnSubmit(a);
            db.SubmitChanges();
        }

        public static New GetByID(int id, HCDataContext db)
        {
            return db.News.Where(
                ik => ik.NewsID == id).FirstOrDefault();
        }

        public static New GetByID(int id)
        {
            return GetByID(id, new HCDataContext());
        }
    }
}